package cn.mihoyo.system.controller;

import cn.mihoyo.base.util.AjaxResult;
import cn.mihoyo.base.util.PageList;
import cn.mihoyo.system.domain.Detail;
import cn.mihoyo.system.query.DetailQuery;
import cn.mihoyo.system.service.IDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/detail")
public class DetailController {
    @Autowired
    private IDetailService detailService; 

    @GetMapping
    public List<Detail> findAll(){
        return detailService.findAll();
    }

    @GetMapping("/{id}")
    public Detail findById(@PathVariable("id") Long id){
        return detailService.findById(id);
    }

    @GetMapping("/findByids/{id}")
    public List<Detail> findByIds(@PathVariable("id") Long id){
        return detailService.findByIds(id);
    }

    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            detailService.delete(id);
            return AjaxResult.me();
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.fail();
        }
    }

    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody Detail employee){
        try {
            if(employee.getId() == null || employee.getId() == 0){
                detailService.add(employee);
            }else {
                detailService.update(employee);
            }
            return AjaxResult.me();
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.fail();
        }
    }

    @PostMapping
    public PageList queryByPage(@RequestBody DetailQuery query){
        return detailService.queryByPage(query);
    }

    @GetMapping("/findNurseState")
    public List<Detail> findNurseState() {
        return detailService.findNurseState();
    }
    @GetMapping("/findBedState")
    public List<Detail> findBedState() {
        return detailService.findBedState();
    }
    @GetMapping("/findOldManSex")
    public List<Detail> findOldManSex() {
        return detailService.findOldManSex();
    }
    @GetMapping("/findOldManPhysical")
    public List<Detail> findOldManPhysical() {
        return detailService.findOldManPhysical();
    }

}
